// pages/user/pj/pj.js
var app = getApp()
var httpService = app.data.service;
Page({

  /**
   * 页面的初始数据
   */
  data: {

    orderId:0,
    star1: [false, false, false, false, false],
    num1:5,
    star2: [false, false, false, false, false],
    num2: 5,
    star3: [false, false, false, false, false],
    num3: 5,
    content:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orderId:options.orderId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },

  /**
   * 第一个评价
   */
  click1:function(e){
    //console.log(e.currentTarget.id);
    var starNum = e.currentTarget.id;
    var that = this;
    var star = [];
    for(var i =0;i<5;i++){
      if (i < starNum){
        star[i] = true;
      }else{
        star[i] = false;
      }
    }
    //console.log(star);
    that.setData({
      star1: star,
      num1:starNum
    })
  },
  click2: function (e) {
    //console.log(e.currentTarget.id);
    var starNum = e.currentTarget.id;
    var that = this;
    var star = [];
    for (var i = 5; i < 10; i++) {
      if (i < starNum) {
        star[i-5] = true;
      } else {
        star[i-5] = false;
      }
    }
    //console.log(star);
    that.setData({
      star2: star,
      num2: starNum-5
    })
  },
  click3: function (e) {
    //console.log(e.currentTarget.id);
    var starNum = e.currentTarget.id;
    var that = this;
    var star = [];
    for (var i = 10; i < 15; i++) {
      if (i < starNum) {
        star[i-10] = true;
      } else {
        star[i-10] = false;
      }
    }
    //console.log(star);
    that.setData({
      star3: star,
      num3: starNum-10
    })
  },
  /**
   * 输入框的值
   */
  bindInput:function(e){
    this.setData({
      content:e.detail.value
    })
  },


  /**
  * 立即评价
  */
  doPJ:function(){
    var that = this;
    //console.log(that.data.content)
    wx.request({
      url: httpService +'/index.php/yuyuepj',
      data:{
        orderId: that.data.orderId,
        num1: that.data.num1,
        num2: that.data.num2,
        num3: that.data.num3,
        content: that.data.content
      },
      success:function(res){
        wx.showLoading({
          title: '评价成功！',
        })
        setTimeout(function () {
          wx.hideLoading()
          wx.reLaunch({
            url: '/pages/user/user'
          })
        }, 1000)
      }
    })
  }

})